import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:get/get.dart';
import 'package:mziot/app/config/constant.dart';
import 'package:mziot/app/config/design.dart';
import 'package:mziot/app/modules/init/controllers/init_controller.dart';
import 'package:mziot/app/routes/app_pages.dart';
import 'package:mziot/app/tools/global_const.dart';
import 'package:mziot/app/tools/tools.dart';
import 'package:mziot/generated/locales.g.dart';

class HelpView extends GetView<InitController> {
  bool isPush = false;

  HelpView({Key? key}) : super(key: key) {
    if (Get.arguments != null) {
      isPush = Get.arguments;
    }
    controller.fetchGuide(isPush: isPush);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: !isPush
          ? null
          : AppBar(
              title: Text(LocaleKeys.mine_help.tr),
            ),
      body: Obx(() {
        return Swiper(
          itemCount: controller.guideList.length,
          controller: controller.swiperController,
          loop: false,
          physics: ClampingScrollPhysics(),
          itemBuilder: (ctx, index) {
            Map<String, dynamic> model = controller.guideList[index];
            String url = model['img'];

            return GestureDetector(
              onTap: () async {
                if (isPush) {
                  return;
                }
                if(index == controller.guideList.length-1) {
                  GlobalConst.sharedPreferences?.setString(Constant.kInstall, 'value');
                  AppPages.INITIAL();
                } else {
                  controller.swiperController.move(index+1);
                }
              },
              child: CachedNetworkImage(
                imageUrl: url,
                fit: BoxFit.contain,
                placeholder: (ctx, text) {
                  return SpinKitCircle(
                    color: MColor.skin,
                    size: 40.0,
                  );
                },
              ),
            );
          },
        );
      }),
    );
  }
}
